﻿using System.Diagnostics;
using System.Web.Mvc;
using SlamCms.Data;
using SlamCms.Web;
using SlamCms.Web.Mvc;

namespace SlamCms.Areas._admin.Controllers
{
	public class VersionController : AdminBaseController
	{
		[HttpGet]
		[AuthorizeTo(AuthorizeTo.All)]
		[AuthorizeRemoteAddress(AuthorizeRemoteAddressScope.Local)]
		public JsonResult Index()
		{
			var slamCmsAssembly = typeof(SlamCmsContext).Assembly;
			var slamCmsAssemblyVersionInfo = FileVersionInfo.GetVersionInfo(slamCmsAssembly.Location);
			var slamCmsAssemblyName = slamCmsAssembly.GetName();
			var slamCmsCoreAssembly = typeof(DataContext).Assembly;
			var slamCmsCoreAssemblyVersionInfo = FileVersionInfo.GetVersionInfo(slamCmsCoreAssembly.Location);
			var slamCmsCoreAssemblyName = slamCmsCoreAssembly.GetName();

			return Json(new
			{
				SlamCms = new
				{
					FileVersion = slamCmsAssemblyVersionInfo.FileVersion,
					ProductVersion = slamCmsAssemblyVersionInfo.ProductVersion,
					AssemblyVersion = slamCmsAssemblyName.Version.ToString()
				},
				SlamCmsCore = new
				{
					FileVersion = slamCmsCoreAssemblyVersionInfo.FileVersion,
					ProductVersion = slamCmsCoreAssemblyVersionInfo.ProductVersion,
					AssemblyVersion = slamCmsCoreAssemblyName.Version.ToString()
				}
			}, JsonRequestBehavior.AllowGet);
		}
	}
}
